import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import AppMainParent from '@/layout/components/AppMainParent'

/* Router Modules */
// import componentsRouter from './modules/components'
// import chartsRouter from './modules/charts'
// import tableRouter from './modules/table'
// import nestedRouter from './modules/nested'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
    {
        path: '/redirect',
        component: Layout,
        hidden: true,
        children: [
            {
                path: '/redirect/:path(.*)',
                component: () => import('@/views/redirect/index')
            }
        ]
    },
    {
        path: '/login',
        component: () => import('@/views/login/index'),
        hidden: true
    },
    {
        path: '/auth-redirect',
        component: () => import('@/views/login/auth-redirect'),
        hidden: true
    },
    {
        path: '/404',
        component: () => import('@/views/error-page/404'),
        hidden: true
    },
    {
        path: '/401',
        component: () => import('@/views/error-page/401'),
        hidden: true
    },

    {
        path: '/',
        component: Layout,
        redirect: '/dashboard',
        children: [
            {
                path: 'dashboard',
                component: () => import('@/views/dashboard/index'),
                name: 'Dashboard',
                meta: {title: '首页', icon: 'dashboard', affix: true}
            }
        ],
        hidden: true
    },
    {
        path: '/mall/order/print',
        component: () => import('@/views/mall/order/Print'),
        meta: {roles: ['mall']},
        hidden: true
    },
    {
        path: '/arrange/passenger',
        name:'IntercityArrangePassenger',
        component: () => import('@/views/intercity/arrange/Passenger'),
        meta: {roles: ['passenger_print']},
        hidden: true
    }


]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
    {
        path: 'food',
        component: AppMainParent,
        meta: {title: '点餐系统', icon: 'guide', roles: ['food']},
        children: [
           {
               path: '/food',
               component: Layout,
               meta: {title: '点餐系统', icon: 'guide', roles: ['food_index']},
               redirect: 'noRedirect',
               children: [
                   {
                       path: 'order',
                       component: () => import('@/views/food/order/index'),
                       name: 'FoodOrder',
                       meta: {title: '订单管理', icon: 'el-icon-s-order', noCache: false, roles: ['food_order']}
                   }, {
                       path: 'goods',
                       component: () => import('@/views/food/goods/index'),
                       name: 'FoodGoodsIndex',
                       meta: {title: '菜品管理', icon: 'el-icon-goods', noCache: false, roles: ['food_manage']},
                   }, {
                       path: 'goodsUpdate',
                       component: () => import('@/views/food/goods/Update'),
                       name: 'FoodGoodsUpdate',
                       meta: {title: '编辑菜品', icon: 'icon', noCache: true, roles: ['food_manage']},
                       hidden: true,
                   }, {
                       path: 'goodsClass',
                       component: () => import('@/views/food/goods-class/index'),
                       name: 'FoodClassIndex',
                       meta: {title: '菜品分类', icon: 'el-icon-folder', noCache: false, roles: ['food_class']}
                   }, {
                       path: 'spec',
                       component: () => import('@/views/food/spec/index'),
                       name: 'FoodSpecIndex',
                       meta: {title: '菜品规格', icon: 'el-icon-folder', noCache: false, roles: ['food_spec']}
                   }, {
                       path: 'goodsType',
                       component: () => import('@/views/food/goods-type/index'),
                       name: 'FoodGoodsTypeIndex',
                       meta: {title: '菜品类型', icon: 'el-icon-folder', noCache: false, roles: ['food_type']}
                   }
               ]
           }
        ]
    },
    {
        path: 'intercity',
        component: AppMainParent,
        meta: {title: '城际系统', icon: 'guide', roles: ['intercity']},
        children: [
           {
               path: '/ticketOrder',
               component: Layout,
               meta: {title: '订单管理', icon: 'guide', roles: ['order']},
               redirect: 'noRedirect',
               children: [
                   {
                       path: 'index',
                       component: () => import('@/views/intercity/ticket-order/index'),
                       name: 'TicketOrderIndex',
                       meta: {title: '车票订单管理', icon: 'icon', noCache: false, roles: ['order_list']}
                   },{
                       path: 'create',
                       component: () => import('@/views/intercity/ticket-order/create'),
                       name: 'TicketOrderCreate',
                       meta: {title: '代客下单', icon: 'icon', noCache: false, roles: ['order_list']}
                   },{
                       path: 'change',
                       component: () => import('@/views/intercity/ticket-order/Change'),
                       name: 'TicketOrderChange',
                       hidden: true,
                       meta: {title: '改签', icon: 'icon', noCache: true, roles: ['order_list']}
                   }
               ]
           },
           {
               path: '/arrange',
               component: Layout,
               meta: {title: '班次管理', icon: 'guide', roles: ['arrange']},
               redirect: 'noRedirect',
               children: [
                   {
                       path: 'list',
                       component: () => import('@/views/intercity/arrange/index'),
                       name: 'ArrangeList',
                       meta: {title: '班次管理', icon: 'icon', noCache: false, roles: ['arrange']}
                   }, {
                       path: 'activities',
                       component: () => import('@/views/intercity/discountedActivities/index'),
                       name: 'IntercityDiscountedActivitiesList',
                       meta: {title: '活动管理', icon: 'icon', noCache: false, roles: ['activities']}
                   }
               ]
           },

           {
               path: '/line',
               component: Layout,
               meta: {title: '线路管理', icon: 'el-icon-guide', roles: ['line']},
               redirect: 'noRedirect',
               children: [ {
                       path: 'lineSection',
                       component: () => import('@/views/intercity/line-section/index'),
                       name: 'lineSection',
                       meta: {title: '线路段管理', icon: 'icon', noCache: false, roles: ['line_section']}
                   },{
                       path: 'line',
                       component: () => import('@/views/intercity/line/index'),
                       name: 'LineList',
                       meta: {title: '线路管理', icon: 'icon', noCache: false, roles: ['line']}
                   }, {
                       path: 'via',
                       component: () => import('@/views/intercity/line-via/index'),
                       name: 'via',
                       hidden: true,
                       meta: {title: '途经点管理', icon: 'icon', noCache: false, roles: ['line']}
                   }, {
                       path: 'lineGroup',
                       component: () => import('@/views/intercity/line-group/index'),
                       name: 'LineGroupList',
                       meta: {title: '线路组管理', icon: 'icon', noCache: false, roles: ['line_group']}
                   },{
                       path: 'lineGroupTotal',
                       component: () => import('@/views/intercity/line-group-total/index'),
                       name: 'lineGroupTotal',
                       meta: {title: '总线路组管理', icon: 'icon', noCache: false, roles: ['line_total_line_group']}
                   },{
                       path: 'carPark',
                       component: () => import('@/views/intercity/car-park/index'),
                       name: 'carPark',
                       meta: {title: '车场管理', icon: 'el-icon-location-outline', noCache: false, roles: ['car_park']}
                   },{
                       path: 'station',
                       component: () => import('@/views/intercity/station/index'),
                       name: 'station',
                       meta: {title: '站点管理', icon: 'el-icon-location', noCache: false, roles: ['station']}
                   },{
                       path: 'carParkFence',
                       component: () => import('@/views/intercity/car-park-fence/index'),
                       name: 'carParkFence',
                       hidden: true,
                       meta: {title: '围栏管理', icon: 'el-icon-map-location', noCache: true, roles: ['car_park']}
                   },{
                       path: 'lineSectionSeatList',
                       component: () => import('@/views/intercity/line-section-seat/index'),
                       name: 'lineSectionSeatList',
                       hidden: true,
                       meta: {title: '线路段座位价格', icon: 'icon', noCache: false, roles: ['line_section']}
                   },{
                       path: 'lineSectionVersion',
                       component: () => import('@/views/intercity/line-section-version/index'),
                       name: 'lineSectionVersion',
                       hidden: true,
                       meta: {title: '线路版本管理', icon: 'icon', noCache: false, roles: ['line_section']}
                   },{
                       path: 'batchAddLineSection',
                       component: () => import('@/views/intercity/line-section/batchAddLineSection'),
                       name: 'batchAddLineSection',
                       hidden: true,
                       meta: {title: '批量添加子线路', icon: 'icon', noCache: false, roles: ['line_section']}
                   },{
                       path: 'batchAddLineSectionSeatPrice',
                       component: () => import('@/views/intercity/line-section-seat/batchAddLineSectionSeatPrice'),
                       name: 'batchAddLineSectionSeatPrice',
                       hidden: true,
                       meta: {title: '批量添加座位价格', icon: 'icon', noCache: false, roles: ['line_section']}
                   }
               ]
           }
        ]
    },
    {
        path: 'biz',
        component: AppMainParent,
        meta: {title: '业务系统', icon: 'guide', roles: ['biz']},
        children: [
           {
               path: '/mall',
               meta: {title: '商城管理', icon: 'el-icon-s-shop', roles: ['mall']},
               component: Layout,
               redirect: 'noRedirect',
               children: [
                   {
                       path: 'order',
                       component: () => import('@/views/mall/order/List'),
                       name: 'MallOrderList',
                       meta: {title: '订单管理', icon: 'el-icon-s-order', noCache: false, roles: ['mall_order']}
                   }, {
                       path: 'goods',
                       component: () => import('@/views/mall/goods/index'),
                       name: 'MallGoodsList',
                       meta: {title: '商品管理', icon: 'el-icon-goods', noCache: false, roles: ['mall_goods']},
                   }, {
                       path: 'goodsUpdate',
                       component: () => import('@/views/mall/goods/Update'),
                       name: 'MallGoodsUpdate',
                       meta: {title: '编辑商品', icon: 'icon', noCache: true, roles: ['mall_goods']},
                       hidden: true,
                   }, {
                       path: 'design',
                       component: () => import('@/views/mall/design/List'),
                       name: 'MallDesignList',
                       meta: {title: '商品系列', icon: 'el-icon-folder', noCache: false, roles: ['mall_design']}
                   }, {
                       path: 'goodsClass',
                       component: () => import('@/views/mall/goods-class/List'),
                       name: 'MallGoodsClassList',
                       meta: {title: '商品分类', icon: 'el-icon-folder', noCache: false, roles: ['mall_goods_class']}
                   }, {
                       path: 'spec',
                       component: () => import('@/views/mall/spec/List'),
                       name: 'MallSpecList',
                       meta: {title: '商品规格', icon: 'el-icon-folder', noCache: false, roles: ['mall_spec']}
                   }, {
                       path: 'goodsType',
                       component: () => import('@/views/mall/goods-type/List'),
                       name: 'MallGoodsTypeList',
                       meta: {title: '商品类型', icon: 'el-icon-folder', noCache: false, roles: ['mall_goods_type']}
                   }, {
                       path: 'brand',
                       component: () => import('@/views/mall/brand/List'),
                       name: 'MallBrandList',
                       meta: {title: '品牌管理', icon: 'el-icon-s-flag', noCache: false, roles: ['mall_brand']}
                   }, {
                       path: 'express',
                       component: () => import('@/views/mall/express/List'),
                       name: 'MallExpressList',
                       meta: {title: '物流管理', icon: 'el-icon-truck', noCache: false, roles: ['mall_express']}
                   }, {
                       path: 'goodsRecommendType',
                       component: () => import('@/views/mall/goods-recommend-type/index'),
                       name: 'goodsRecommendType',
                       meta: {title: '推荐类型管理', icon: 'el-icon-tickets', noCache: false, roles: ['mall_goods']},
                       hidden: true
                   }, {
                       path: 'goodsRecommend',
                       component: () => import('@/views/mall/goods-recommend/index'),
                       name: 'goodsRecommend',
                       hidden: true,
                       meta: {title: '推荐列表', icon: 'el-icon-tickets', noCache: true, roles: ['mall_goods']}
                   }
               ]
           },
           {
               path: '/cms',
               component: Layout,
               meta: {title: '内容管理', icon: 'el-icon-document', roles: ['cms']},
               redirect: 'noRedirect',
               children: [
                   {
                       path: 'article',
                       component: () => import('@/views/cms/article/List'),
                       name: 'CmsArticleList',
                       meta: {title: '文章列表', icon: 'el-icon-tickets', noCache: false, roles: ['cms_article']}
                   }, {
                       path: 'articleUpdate',
                       component: () => import('@/views/cms/article/Update'),
                       name: 'CmsArticleUpdate',
                       hidden: true,
                       meta: {title: '文章管理', icon: 'el-icon-tickets', noCache: true, roles: ['cms_article']}
                   }, {
                       path: 'articleType',
                       component: () => import('@/views/cms/article-type/List'),
                       name: 'CmsArticleType',
                       hidden: true,
                       meta: {
                           title: '文章类型',
                           icon: 'el-icon-document-copy',
                           noCache: false,
                           roles: ['cms_article_type']
                       }
                   }, {
                       path: 'articleRecommendType',
                       component: () => import('@/views/cms/articleRecommendType/List'),
                       name: 'CmsArticleRecommendTypeList',
                       hidden: true,
                       meta: {title: '推荐管理', icon: 'el-icon-tickets', noCache: false, roles: ['cms_article']}
                   }, {
                       path: 'articleRecommend',
                       component: () => import('@/views/cms/articleRecommend/List'),
                       name: 'CmsArticleRecommendList',
                       hidden: true,
                       meta: {title: '推荐列表', icon: 'el-icon-tickets', noCache: true, roles: ['cms_article']}
                   }, {
                       path: 'keyword',
                       component: () => import('@/views/cms/keyword/List'),
                       name: 'CmsKeywordList',
                       meta: {title: '关键字管理', icon: 'el-icon-guide', noCache: false, roles: ['cms_keyword']}
                   }, {
                       path: 'ad',
                       component: () => import('@/views/cms/ad/List'),
                       name: 'CmsAdList',
                       meta: {title: '广告管理', icon: 'el-icon-guide', noCache: false, roles: ['cms_ad']}
                   }, {
                       path: 'adType',
                       component: () => import('@/views/cms/ad-type/List'),
                       name: 'CmsAdType',
                       hidden: true,
                       meta: {title: '广告类型', icon: 'el-icon-document-copy', noCache: false, roles: ['cms_ad_type']}
                   }, {
                       path: 'link',
                       component: () => import('@/views/cms/link/List'),
                       name: 'CmsLinkList',
                       meta: {title: '友情链接', icon: 'el-icon-document-copy', noCache: false, roles: ['cms_link']}
                   }
               ]
           },
           {
               path: '/user',
               component: Layout,
               meta: {title: '用户管理', icon: 'el-icon-user-solid', roles: ['user']},
               redirect: 'noRedirect',
               children: [
                   {
                       path: 'account',
                       component: () => import('@/views/user/account/List'),
                       name: 'UserAccountList',
                       meta: {title: '会员管理', icon: 'el-icon-user', noCache: false, roles: ['user_account']}
                   }, {
                       path: 'credit',
                       component: () => import('@/views/user/credit/List'),
                       name: 'UserCreditList',
                       meta: {title: '会员积分', icon: 'el-icon-medal', noCache: false, roles: ['user_credit']}
                   }, {
                       path: 'seller',
                       component: () => import('@/views/user/seller/List'),
                       name: 'UserSellerList',
                       meta: {title: '商家列表', icon: 'el-icon-s-shop', noCache: false, roles: ['user_seller']}
                   },
                   {
                       path: 'driver',
                       component: () => import('@/views/user/driver/index'),
                       name: 'driverIndex',
                       meta: {title: '司机管理', icon: 'el-icon-truck', noCache: false, roles: ['user_driver']}

                   }, {
                       path: 'sellerAdd',
                       component: () => import('@/views/user/seller/Add'),
                       name: 'sellerAdd',
                       meta: {title: '商家管理', icon: 'el-icon-s-shop', noCache: false, roles: ['user_seller']},
                       hidden: true,
                   }, {
                       path: 'industryType',
                       component: () => import('@/views/user/industry-type/List'),
                       name: 'industryType',
                       meta: {title: '行业类型', icon: 'el-icon-medal', noCache: false, roles: ['user_industry_type']}
                   }, {
                       path: 'comment',
                       component: () => import('@/views/user/comment/index'),
                       name: 'comment',
                       meta: {title: '用户评论', icon: 'el-icon-medal', noCache: false, roles: ['user_comment']}
                   }, {
                       path: 'report',
                       component: () => import('@/views/user/report/index'),
                       name: 'report',
                       meta: {title: '问题反馈', icon: 'el-icon-medal', noCache: false, roles: ['user_report']}
                   }, {
                       path: 'withdrawDeposit',
                       component: () => import('@/views/user/withdrawDeposit/index'),
                       name: 'report',
                       meta: {title: '提现申请', icon: 'el-icon-medal', noCache: false, roles: ['user_withdraw_deposit']}
                   }
               ]
           },{
               path: '/vehicle',
               component: Layout,
               meta: {title: '车辆管理', icon: 'el-icon-truck', roles: ['vehicle']},
               redirect: 'noRedirect',
               children: [
                   {
                       path: 'vehicle',
                       component: () => import('@/views/user/vehicle/index'),
                       name: 'vehicle',
                       meta: {title: '车辆管理', icon: 'el-icon-truck', noCache: false, roles: ['vehicle_list']}
                   }, {
                       path: 'type',
                       component: () => import('@/views/user/vehicle-type/index'),
                       name: 'VehicleType',
                       meta: {title: '车型管理', icon: 'el-icon-truck', noCache: false, roles: ['vehicle_type']}
                   }, {
                       path: 'seat',
                       component: () => import('@/views/user/vehicle-type-seat/index'),
                       name: 'VehicleTypeSeat',
                       hidden: true,
                       meta: {title: '车型座位管理', icon: 'icon', noCache: false, roles: ['vehicle_type']}
                   }, {
                       path: 'vehicleBrand',
                       component: () => import('@/views/user/vehicleBrand/index'),
                       name: 'vehicleBrand',
                       hidden: true,
                       meta: {title: '车辆品牌管理', icon: 'icon', noCache: false, roles: ['vehicle_list']}
                   }
               ]
           },
           {
               path: '/message',
               component: Layout,
               meta: {title: '消息管理', icon: 'el-icon-chat-line-round', roles: ['message']},
               redirect: 'noRedirect',
               children: [
                   {
                       path: 'wxMessage',
                       component: () => import('@/views/message/wx/Send'),
                       name: 'wxMessage',
                       meta: {title: '发送微信模板消息', icon: 'el-icon-notebook-2', noCache: false, roles: ['message_send']}
                   }, {
                       path: 'record',
                       component: () => import('@/views/message/record/List'),
                       name: 'MessageRecordList',
                       meta: {title: '消息日志', icon: 'el-icon-tickets', noCache: false, roles: ['message_record']}
                   }, {
                       path: 'messageTask',
                       component: () => import('@/views/message/task/List'),
                       name: 'messageTask',
                       meta: {title: '任务管理', icon: 'el-icon-s-flag', noCache: false, roles: ['message_task']}
                   }, {
                       path: 'template',
                       component: () => import('@/views/message/template/List'),
                       name: 'MessageTemplateList',
                       meta: {title: '消息模版管理', icon: 'el-icon-notebook-2', noCache: false, roles: ['message_template']}
                   }
               ]
           },
        ]
    },
    {
        path: 'system',
        component: AppMainParent,
        meta: {title: '系统设置', icon: 'guide', roles: ['system']},
        children: [
           {
               path: '/system',
               component: Layout,
               meta: {title: '系统中心', icon: 'el-icon-s-tools', roles: ['system']},
               redirect: 'noRedirect',
               children: [
                   {
                       path: 'admin',
                       component: () => import('@/views/system/admin/List'),
                       name: 'SystemAdminList',
                       meta: {title: '后台账号管理', icon: 'el-icon-s-custom', noCache: false, roles: ['system_admin']}
                   }, {
                       path: 'role',
                       component: () => import('@/views/system/role/List'),
                       name: 'SystemRoleList',
                       meta: {title: '角色管理', icon: 'peoples', noCache: false, roles: ['system_role']}
                   },  {
                       path: 'permission',
                       component: () => import('@/views/system/permission/index'),
                       name: 'SystemPermissionIndex',
                       meta: {title: '权限管理', icon: 'peoples', noCache: false, roles: ['system_permission']}
                   }, {
                       path: 'config',
                       component: () => import('@/views/system/config/index'),
                       name: 'SystemConfigList',
                       meta: {title: '系统配置', icon: 'el-icon-setting', noCache: false, roles: ['system_config']}
                   },
                   {
                       path: 'SystemNotify',
                       component: () => import('@/views/system/notify/List'),
                       name: 'SystemNotify',
                       meta: {title: '系统通知', icon: 'el-icon-s-check', noCache: false, roles: ['system_notify']}
                   }, {
                       path: 'region',
                       component: () => import('@/views/system/region/List'),
                       name: 'region',
                       meta: {title: '地区管理', icon: 'el-icon-location', noCache: false, roles: ['system_region']}
                   }, {
                       path: 'log',
                       component: () => import('@/views/system/log/List'),
                       name: 'SystemLogList',
                       meta: {title: '操作日志', icon: 'el-icon-postcard', noCache: false, roles: ['system_log']}
                   }
               ]
           },{
               path: '/app-version',
               component: Layout,
               meta: {title: 'APP管理', icon: 'el-icon-s-tools', roles: ['app_version']},
               redirect: 'noRedirect',
               children: [
                   {
                       path: 'version',
                       component: () => import('@/views/system/app-version/index'),
                       name: 'AppVersionList',
                       meta: {title: 'APP版本管理', icon: 'el-icon-s-custom', noCache: false, roles: ['app_version']}
                   }
               ]
           }
        ]
    },

// 404 page must be placed at the end !!!
    {path: '*', redirect: '/404', hidden: true}

]

const createRouter = () => new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({y: 0}),
    routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

export default router
